/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */

package cn.qidisoft.edu.hzjt.controller.bjxxclassworkInstead;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.DateUtil;
import cn.qidisoft.core.util.StringUtils;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.model.BjxxClassWorkInstead;
import cn.qidisoft.edu.hzjt.model.BjxxClassWorkInsteadAtt;
import cn.qidisoft.edu.hzjt.model.Employee;
import cn.qidisoft.edu.hzjt.model.Student;
import cn.qidisoft.edu.hzjt.model.UserEmployee;
import cn.qidisoft.edu.hzjt.service.IBjxxClassWorkInsteadAttService;
import cn.qidisoft.edu.hzjt.service.IBjxxClassWorkInsteadService;
import cn.qidisoft.edu.hzjt.service.ICommonService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import cn.qidisoft.edu.hzjt.utils.SyncValdateJson;
import cn.qidisoft.edu.hzjt.utils.validationSqlString;
import cn.qidisoft.edu.hzjt.vo.BjxxClassWorkInsteadBean;
import cn.qidisoft.edu.hzjt.vo.EmployeeBean;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: SyncBjxxClassWorkInsteadController.java, v 0.1 2018年12月5日 上午11:57:50 hhl Exp $
 */
@Controller
@RequestMapping(value = "syncBjxxClassWorkInstead")
public class SyncBjxxClassWorkInsteadController {
  protected static final LoggerAdapter LOGGER =
      LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
  @Autowired
  private IBjxxClassWorkInsteadService bjxxClassWorkInsteadService;

  @Autowired
  private ICommonService commonService;

  @Autowired
  private IBjxxClassWorkInsteadAttService bjxxClassWorkInsteadAttService;

  /**
   * 顶班申请列表
   * 
   * @param SyncValdateSecret
   * @param type
   * @param uid
   * @param orderField
   * @param orderFlag
   * @param currPage
   * @param pageSize
   * @return
   */
  /*
   * @RequestMapping(value = "/bjxxClassWorkInsteadList", produces =
   * "application/json;charset=utf-8")
   */
  @RequestMapping(value = "/bjxxClassWorkInsteadList", produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> bjxxClassWorkInsteadList(HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "orderField", required = true) String orderField, // 排序字段
      @RequestParam(value = "orderFlag", required = true) String orderFlag, // 排序方式
      @RequestParam(value = "currPage", required = true) Integer currPage,
      @RequestParam(value = "pageSize", required = true) Integer pageSize) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {

      XSSInterceptorMicro eXssInterceptorMicro = new XSSInterceptorMicro();
      boolean ok = eXssInterceptorMicro.verifyException(request, response);
      if (ok == false) {
        dataMap.put("status", "error");
        dataMap.put("msg", "对不起！您输入内容包含有非法字符,请检查参数");
        return dataMap;
      }
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }
        if (currPage <= 0 || pageSize <= 0) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数currPage或pageSize的值无效,请您核查您的信息是否有效!");
          return dataMap;
        }
        if (StringUtils.isNullValue(orderField)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "排序字段不能为空!");
          return dataMap;
        }
        if (StringUtils.isNullValue(orderFlag)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "排序方式不能为空!");
          return dataMap;
        }

        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        if (userEmployee != null && userEmployee.getUid() != null) {
          data.setEmpid(userEmployee.getEmid() == null ? null : userEmployee.getEmid());
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息");
          return dataMap;
        }
        Page page = new Page();
        page.setCurrPage(currPage == null ? 0 : Integer.valueOf(currPage));
        page.setPageSize(pageSize == null ? Constant.PageSize : Integer.valueOf(pageSize));
        data.setOrderField(orderField);
        data.setOrderFlag(orderFlag);
        PaginationBean<BjxxClassWorkInstead> paginationBean =
            bjxxClassWorkInsteadService.queryPageList(data, page);
        List<BjxxClassWorkInsteadBean> list = new ArrayList<BjxxClassWorkInsteadBean>();
        if (paginationBean.getPageList() != null && !paginationBean.getPageList().isEmpty()) {
          for (BjxxClassWorkInstead r : paginationBean.getPageList()) {
            BjxxClassWorkInsteadBean bean = new BjxxClassWorkInsteadBean();
            bean.setDbid(r.getDbid());
            bean.setEmpid(r.getEmpid());
            bean.setXm(r.getXm());
            bean.setZgh(r.getZgh());
            bean.setApplydate(r.getApplydate() == null ? null
                : DateUtil.formatDate2Str(r.getApplydate(), "yyyy-MM-dd"));
            bean.setStates(r.getStates());
            bean.setDbempid(r.getDbempid());
            bean.setDbxm(r.getDbxm());
            bean.setDbzgh(r.getDbzgh());
            bean.setKsrq(
                r.getKsrq() == null ? null : DateUtil.formatDate2Str(r.getKsrq(), "yyyy-MM-dd"));
            bean.setJsrq(
                r.getJsrq() == null ? null : DateUtil.formatDate2Str(r.getJsrq(), "yyyy-MM-dd"));
            bean.setKsrqfw(r.getKsrqfw());
            bean.setJsrqfw(r.getJsrqfw());
            bean.setDays(String.valueOf(r.getDays()));
            bean.setReasons(r.getReasons());
            bean.setRemark(r.getRemark());
            bean.setAuditorid(r.getAuditorid());
            bean.setAuditorname(r.getAuditorname());
            bean.setAudittime(r.getAudittime() == null ? null
                : DateUtil.formatDate2Str(r.getAudittime(), "yyyy-MM-dd"));
            bean.setAuditresult(r.getAuditresult());
            list.add(bean);
          }
          dataMap.put("dataList", list);
          dataMap.put("status", "success");
          dataMap.put("msg", "查询成功");
        } else {
          dataMap.put("dataList", list);
          dataMap.put("status", "success");
          dataMap.put("msg", "查询成功");
        }
      }
    } catch (Exception e) {
      LOGGER.error("查询时调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "查询信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 顶班申请新增接口
   * 
   * @param SyncValdateSecret
   * @param dataJson
   * @return
   */
  @RequestMapping(value = "/addBjxxClassWorkInstead", produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> addBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "dataJson", required = true) String dataJson) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean b = SyncValdateJson.SyncValdateJson(SyncValdateSecret, dataJson, dataMap);
      if (b == true) {
        BjxxClassWorkInsteadBean bean = (BjxxClassWorkInsteadBean) SyncValdateJson
            .parseJsonToBean(dataJson, BjxxClassWorkInsteadBean.class);
        if (bean == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "未找到可以同步的数据信息");
          return dataMap;
        } else {
          if (uid == null || StringUtils.isNullValue(type)) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
            return dataMap;
          }
          UserEmployee user = new UserEmployee();
          user.setUid(uid);
          UserEmployee userEmployee = commonService.queryUserByEmployee(user);
          if (userEmployee != null && userEmployee.getEmid() != null) {

          } else {
            dataMap.put("status", "error");
            dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
            return dataMap;
          }

          BjxxClassWorkInstead data = new BjxxClassWorkInstead();
          if (bean.getEmpid() == null) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班申请人ID不能为空!");
            return dataMap;
          } else {
            data.setEmpid(bean.getEmpid());
          }

          if (StringUtils.isNullValue(bean.getXm())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班申请人姓名不能为空!");
            return dataMap;
          } else {
            data.setXm(bean.getXm());
          }

          if (StringUtils.isNullValue(bean.getZgh())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班申请人工号不能为空!");
            return dataMap;
          } else {
            data.setZgh(bean.getZgh());
          }

          if (StringUtils.isNullValue(bean.getApplydate())) {
            data.setApplydate(new Date());
          } else {
            data.setApplydate(DateUtil.parseStr2Date(bean.getApplydate(), "yyyy-MM-dd"));
          }
          data.setStates(0);

          String dbempidList = null;
          if (StringUtils.isNullValue(bean.getDbempidList())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班人ID不能为空!");
            return dataMap;
          } else {
            dbempidList = bean.getDbempidList();
          }

          if (StringUtils.isNullValue(bean.getKsrq())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班开始日期不能为空!");
            return dataMap;
          } else {
            if (StringUtils.dateFormat(bean.getKsrq(), "yyyy-MM-dd") == false) {
              dataMap.put("status", "error");
              dataMap.put("msg", "参数顶班开始日期格式不正确,格式为：yyyy-MM-dd");
              return dataMap;
            }
            data.setKsrq(DateUtil.parseStr2Date(bean.getKsrq(), "yyyy-MM-dd"));
          }

          if (StringUtils.isNullValue(bean.getJsrq())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班结束日期不能为空!");
            return dataMap;
          } else {
            if (StringUtils.dateFormat(bean.getJsrq(), "yyyy-MM-dd") == false) {
              dataMap.put("status", "error");
              dataMap.put("msg", "参数顶班结束日期格式不正确,格式为：yyyy-MM-dd");
              return dataMap;
            }
            data.setJsrq(DateUtil.parseStr2Date(bean.getJsrq(), "yyyy-MM-dd"));
          }

          if (StringUtils.isNullValue(bean.getKsrqfw())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数开始日期范围不能为空!");
            return dataMap;
          } else {
            data.setKsrqfw(bean.getKsrqfw());
          }

          if (StringUtils.isNullValue(bean.getJsrqfw())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数结束日期范围不能为空!");
            return dataMap;
          } else {
            data.setJsrqfw(bean.getJsrqfw());
          }
          if (StringUtils.isNullValue(bean.getReasons())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班事由不能为空!");
            return dataMap;
          } else {
            if (validationSqlString.lengthSql2008(bean.getReasons()) >= 50) {
              dataMap.put("status", "error");
              dataMap.put("msg", "顶班事由长度过长,请您输入(0~50)个字符长度信息");
              return dataMap;
            }
            data.setReasons(bean.getReasons());
          }
          if (validationSqlString.lengthSql2008(bean.getRemark()) >= 200) {
            dataMap.put("status", "error");
            dataMap.put("msg", "备注由长度过长,请您输入(0~200)个字符长度信息");
            return dataMap;
          }
          data.setRemark(bean.getRemark());

          Calendar cal = Calendar.getInstance();
          cal.setTime(data.getKsrq());
          long time1 = cal.getTimeInMillis();
          cal.setTime(data.getJsrq());
          long time2 = cal.getTimeInMillis();
          long between_days = (time2 - time1) / (1000 * 3600 * 24);
          data.setDays(BigDecimal.valueOf(between_days));
          String gid = bjxxClassWorkInsteadService.add(data);

          BjxxClassWorkInstead data1 = new BjxxClassWorkInstead();
          data1.setGid(gid);
          data1 = bjxxClassWorkInsteadService.queryByPK(data1);

          java.util.List<Employee> list = commonService.getqueryStudentClassByBzr(new Student());
          for (String r : dbempidList.split(",")) {
            for (Employee employee : list) {
              if (employee.getEmid().intValue() == Integer.valueOf(r).intValue()) {
                BjxxClassWorkInsteadAtt att = new BjxxClassWorkInsteadAtt();
                att.setXm(employee.getXm());
                att.setZgh(employee.getZgh());
                att.setEmpid(employee.getEmid());
                att.setParentid(data1.getDbid());
                bjxxClassWorkInsteadAttService.add(att);
                break;
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("添加信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "添加信息失败,网络异常");
      return dataMap;
    }
    dataMap.put("status", "success");
    dataMap.put("msg", "成功");
    return dataMap;
  }

  /**
   * 顶班申请修改接口
   * 
   * @param SyncValdateSecret
   * @param dataJson
   * @return
   */
  @RequestMapping(value = "/updateBjxxClassWorkInstead",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> updateBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "dataJson", required = true) String dataJson) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean b = SyncValdateJson.SyncValdateJson(SyncValdateSecret, dataJson, dataMap);
      if (b == true) {
        BjxxClassWorkInsteadBean bean = (BjxxClassWorkInsteadBean) SyncValdateJson
            .parseJsonToBean(dataJson, BjxxClassWorkInsteadBean.class);
        if (bean == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "未找到可以同步的数据信息");
          return dataMap;
        } else {
          if (uid == null || StringUtils.isNullValue(type)) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
            return dataMap;
          }

          UserEmployee user = new UserEmployee();
          user.setUid(uid);
          UserEmployee userEmployee = commonService.queryUserByEmployee(user);
          if (userEmployee != null && userEmployee.getEmid() != null) {

          } else {
            dataMap.put("status", "error");
            dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
            return dataMap;
          }

          BjxxClassWorkInstead data = new BjxxClassWorkInstead();
          if (bean.getDbid() == null) {
            dataMap.put("status", "error");
            dataMap.put("msg", "顶班ID不能为空!");
            return dataMap;
          } else {
            data.setDbid(bean.getDbid());
          }

          if (bean.getEmpid() == null) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班申请人ID不能为空!");
            return dataMap;
          } else {
            data.setEmpid(bean.getEmpid());
          }

          if (StringUtils.isNullValue(bean.getXm())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班申请人姓名不能为空!");
            return dataMap;
          } else {
            data.setXm(bean.getXm());
          }

          if (StringUtils.isNullValue(bean.getZgh())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班申请人工号不能为空!");
            return dataMap;
          } else {
            data.setZgh(bean.getZgh());
          }

          if (StringUtils.isNullValue(bean.getApplydate())) {
            data.setApplydate(new Date());
          } else {
            data.setApplydate(DateUtil.parseStr2Date(bean.getApplydate(), "yyyy-MM-dd"));
          }
          data.setStates(0);

          String dbempidList = null;
          if (StringUtils.isNullValue(bean.getDbempidList())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班人ID不能为空!");
            return dataMap;
          } else {
            dbempidList = bean.getDbempidList();
          }

          if (StringUtils.isNullValue(bean.getKsrq())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班开始日期不能为空!");
            return dataMap;
          } else {
            if (StringUtils.dateFormat(bean.getKsrq(), "yyyy-MM-dd") == false) {
              dataMap.put("status", "error");
              dataMap.put("msg", "参数顶班开始日期格式不正确,格式为：yyyy-MM-dd");
              return dataMap;
            }
            data.setKsrq(DateUtil.parseStr2Date(bean.getKsrq(), "yyyy-MM-dd"));
          }

          if (StringUtils.isNullValue(bean.getJsrq())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班结束日期不能为空!");
            return dataMap;
          } else {
            if (StringUtils.dateFormat(bean.getJsrq(), "yyyy-MM-dd") == false) {
              dataMap.put("status", "error");
              dataMap.put("msg", "参数顶班结束日期格式不正确,格式为：yyyy-MM-dd");
              return dataMap;
            }
            data.setJsrq(DateUtil.parseStr2Date(bean.getJsrq(), "yyyy-MM-dd"));
          }

          if (StringUtils.isNullValue(bean.getKsrqfw())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数开始日期范围不能为空!");
            return dataMap;
          } else {
            data.setKsrqfw(bean.getKsrqfw());
          }

          if (StringUtils.isNullValue(bean.getJsrqfw())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数结束日期范围不能为空!");
            return dataMap;
          } else {
            data.setJsrqfw(bean.getJsrqfw());
          }
          if (StringUtils.isNullValue(bean.getReasons())) {
            dataMap.put("status", "error");
            dataMap.put("msg", "参数顶班事由不能为空!");
            return dataMap;
          } else {
            if (validationSqlString.lengthSql2008(bean.getReasons()) >= 50) {
              dataMap.put("status", "error");
              dataMap.put("msg", "顶班事由长度过长,请您输入(0~50)个字符长度信息");
              return dataMap;
            }
            data.setReasons(bean.getReasons());
          }
          if (validationSqlString.lengthSql2008(bean.getRemark()) >= 200) {
            dataMap.put("status", "error");
            dataMap.put("msg", "备注由长度过长,请您输入(0~200)个字符长度信息");
            return dataMap;
          }
          data.setRemark(bean.getRemark());

          Calendar cal = Calendar.getInstance();
          cal.setTime(data.getKsrq());
          long time1 = cal.getTimeInMillis();
          cal.setTime(data.getJsrq());
          long time2 = cal.getTimeInMillis();
          long between_days = (time2 - time1) / (1000 * 3600 * 24);
          data.setDays(BigDecimal.valueOf(between_days));
          bjxxClassWorkInsteadService.update(data);

          java.util.List<Employee> list = commonService.getqueryStudentClassByBzr(new Student());
          if (dbempidList != null && !dbempidList.equals("")) {
            BjxxClassWorkInsteadAtt bjxxClassWorkInsteadAtt = new BjxxClassWorkInsteadAtt();
            bjxxClassWorkInsteadAtt.setParentid(data.getDbid());
            bjxxClassWorkInsteadAttService.delete(bjxxClassWorkInsteadAtt);
            for (String r : dbempidList.split(",")) {
              for (Employee employee : list) {
                if (employee.getEmid().intValue() == Integer.valueOf(r).intValue()) {
                  BjxxClassWorkInsteadAtt att = new BjxxClassWorkInsteadAtt();
                  att.setXm(employee.getXm());
                  att.setZgh(employee.getZgh());
                  att.setEmpid(employee.getEmid());
                  att.setParentid(data.getDbid());
                  bjxxClassWorkInsteadAttService.add(att);
                  break;
                }
              }
            }
          } else {
            dataMap.put("status", "error");
            dataMap.put("msg", "顶班人id不能为空,网络异常");
            return dataMap;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 顶班申请详情接口
   * 
   * @param SyncValdateSecret
   * @param dataJson
   * @return
   */
  @RequestMapping(value = "/detailsBjxxClassWorkInstead",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> detailsBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "dbid", required = true) Integer dbid) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }

        if (dbid == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "顶班申请ID不能为空");
          return dataMap;
        }

        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        if (userEmployee != null) {
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
          return dataMap;
        }

        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        data.setDbid(dbid);
        data = bjxxClassWorkInsteadService.queryByPK(data);
        if (data != null && data.getDbid() != null) {

          BjxxClassWorkInsteadBean bean = new BjxxClassWorkInsteadBean();
          bean.setDbid(data.getDbid());
          bean.setEmpid(data.getEmpid());
          bean.setXm(data.getXm());
          bean.setZgh(data.getZgh());
          bean.setApplydate(data.getApplydate() == null ? null
              : DateUtil.formatDate2Str(data.getApplydate(), "yyyy-MM-dd"));
          bean.setStates(data.getStates());
          bean.setDbempid(data.getDbempid());
          bean.setDbxm(data.getDbxm());
          bean.setDbzgh(data.getDbzgh());
          bean.setKsrq(data.getKsrq() == null ? null
              : DateUtil.formatDate2Str(data.getKsrq(), "yyyy-MM-dd"));
          bean.setJsrq(data.getJsrq() == null ? null
              : DateUtil.formatDate2Str(data.getJsrq(), "yyyy-MM-dd"));
          bean.setKsrqfw(data.getKsrqfw());
          bean.setJsrqfw(data.getJsrqfw());
          bean.setDays(String.valueOf(data.getDays()));
          bean.setReasons(data.getReasons());
          bean.setRemark(data.getRemark());
          bean.setAuditorid(data.getAuditorid());
          bean.setAuditorname(data.getAuditorname());
          bean.setAudittime(data.getAudittime() == null ? null
              : DateUtil.formatDate2Str(data.getAudittime(), "yyyy-MM-dd"));
          bean.setAuditresult(data.getAuditresult());
          dataMap.put("data", bean);
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "查询信息失败,网络异常");
          return dataMap;
        }
        dataMap.put("status", "success");
        dataMap.put("msg", "成功");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 
   * 顶班删除接口
   * 
   * @param SyncValdateSecret
   * @param type
   * @param uid
   * @param dbid
   * @return
   */
  @RequestMapping(value = "/deleteBjxxClassWorkInstead",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> deleteBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "idList", required = true) String[] idList) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }
        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        if (userEmployee != null) {
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
          return dataMap;
        }
        if (idList == null || idList.equals("")) {
          dataMap.put("status", "error");
          dataMap.put("msg", "顶班id不能为空!");
          return dataMap;
        }

        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        data.setIds(idList);
        bjxxClassWorkInsteadService.delete(data);
        dataMap.put("status", "success");
        dataMap.put("msg", "成功");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 
   * 顶班提交接口
   * 
   * @param SyncValdateSecret
   * @param type
   * @param uid
   * @param dbid
   * @return
   */
  @RequestMapping(value = "/submitBjxxClassWorkInstead",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> submitBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "dbid", required = true) Integer dbid) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }
        if (dbid == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "顶班申请ID不能为空");
          return dataMap;
        }
        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        if (userEmployee != null) {
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
          return dataMap;
        }
        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        data.setDbid(dbid);
        data = bjxxClassWorkInsteadService.queryByPK(data);
        data.setStates(1);
        data.setAuditresult(null);
        data.setAuditorid(null);
        data.setAuditorname(null);
        data.setAudittime(null);
        bjxxClassWorkInsteadService.update(data);

        dataMap.put("status", "success");
        dataMap.put("msg", "成功");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 
   * 顶班退回接口
   * 
   * @param SyncValdateSecret
   * @param type
   * @param uid
   * @param dbid
   * @return
   */
  @RequestMapping(value = "/sendBackBjxxClassWorkInstead",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> sendBackBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "dbid", required = true) Integer dbid,
      @RequestParam(value = "auditresult") String auditresult) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }

        if (dbid == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "顶班申请ID不能为空");
          return dataMap;
        }
        if (StringUtils.isNullValue(auditresult)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "审核意见不能为空!");
          return dataMap;
        }

        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        if (userEmployee != null) {
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
          return dataMap;
        }
        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        data.setDbid(dbid);
        data = bjxxClassWorkInsteadService.queryByPK(data);
        data.setStates(3);
        data.setAuditresult(auditresult);
        data.setAuditorid(userEmployee.getEmid() == null ? null : userEmployee.getUid());
        data.setAuditorname(userEmployee.getXm());
        data.setAudittime(new Date());
        bjxxClassWorkInsteadService.update(data);

        dataMap.put("status", "success");
        dataMap.put("msg", "成功");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 顶班申请列表
   * 
   * @param SyncValdateSecret
   * @param type
   * @param uid
   * @param orderField
   * @param orderFlag
   * @param currPage
   * @param pageSize
   * @return
   */
  @RequestMapping(value = "/bjxxClassWorkInsteadListAdmin",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> bjxxClassWorkInsteadListAdmin(HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "orderField", required = true) String orderField, // 排序字段
      @RequestParam(value = "orderFlag", required = true) String orderFlag, // 排序方式
      @RequestParam(value = "currPage", required = true) Integer currPage,
      @RequestParam(value = "pageSize", required = true) Integer pageSize) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {

      XSSInterceptorMicro eXssInterceptorMicro = new XSSInterceptorMicro();
      boolean ok = eXssInterceptorMicro.verifyException(request, response);
      if (ok == false) {
        dataMap.put("status", "error");
        dataMap.put("msg", "对不起！您输入内容包含有非法字符,请检查参数");
        return dataMap;
      }
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }
        if (currPage <= 0 || pageSize <= 0) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数currPage或pageSize的值无效,请您核查您的信息是否有效!");
          return dataMap;
        }
        if (StringUtils.isNullValue(orderField)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "排序字段不能为空!");
          return dataMap;
        }
        if (StringUtils.isNullValue(orderFlag)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "排序方式不能为空!");
          return dataMap;
        }

        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        if (userEmployee != null && userEmployee.getUid() != null) {
          data.setEmpid(userEmployee.getEmid() == null ? null : userEmployee.getEmid());
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息");
          return dataMap;
        }
        Page page = new Page();
        page.setCurrPage(currPage == null ? 0 : Integer.valueOf(currPage));
        page.setPageSize(pageSize == null ? Constant.PageSize : Integer.valueOf(pageSize));
        data.setOrderField(orderField);
        data.setOrderFlag(orderFlag);
        PaginationBean<BjxxClassWorkInstead> paginationBean =
            bjxxClassWorkInsteadService.queryPageList_admin(data, page);

        if (paginationBean.getPageList() == null && paginationBean.getPageList().isEmpty()) {
        } else {
          List<BjxxClassWorkInsteadBean> list = new ArrayList<BjxxClassWorkInsteadBean>();
          for (BjxxClassWorkInstead r : paginationBean.getPageList()) {
            BjxxClassWorkInsteadBean bean = new BjxxClassWorkInsteadBean();
            bean.setDbid(r.getDbid());
            bean.setEmpid(r.getEmpid());
            bean.setXm(r.getXm());
            bean.setZgh(r.getZgh());
            bean.setApplydate(r.getApplydate() == null ? null
                : DateUtil.formatDate2Str(r.getApplydate(), "yyyy-MM-dd"));
            bean.setStates(r.getStates());
            bean.setDbempid(r.getDbempid());
            bean.setDbxm(r.getDbxm());
            bean.setDbzgh(r.getDbzgh());
            bean.setKsrq(
                r.getKsrq() == null ? null : DateUtil.formatDate2Str(r.getKsrq(), "yyyy-MM-dd"));
            bean.setJsrq(
                r.getJsrq() == null ? null : DateUtil.formatDate2Str(r.getJsrq(), "yyyy-MM-dd"));
            bean.setKsrqfw(r.getKsrqfw());
            bean.setJsrqfw(r.getJsrqfw());
            bean.setDays(String.valueOf(r.getDays()));
            bean.setReasons(r.getReasons());
            bean.setRemark(r.getRemark());
            bean.setAuditorid(r.getAuditorid());
            bean.setAuditorname(r.getAuditorname());
            bean.setAudittime(r.getAudittime() == null ? null
                : DateUtil.formatDate2Str(r.getAudittime(), "yyyy-MM-dd"));
            bean.setAuditresult(r.getAuditresult());
            list.add(bean);
          }
          dataMap.put("dataList", list);
          dataMap.put("status", "success");
          dataMap.put("msg", "查询成功");
        }
      }
    } catch (Exception e) {
      LOGGER.error("查询时调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "查询信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 顶班申请详情审核端接口
   * 
   * @param SyncValdateSecret
   * @param dataJson
   * @return
   */
  @RequestMapping(value = "/detailsAdminBjxxClassWorkInstead",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> detailsAdminBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "dbid", required = true) Integer dbid) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }
        if (dbid == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "顶班ID不能为空");
          return dataMap;
        }
        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        if (userEmployee != null) {
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
          return dataMap;
        }

        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        data.setDbid(dbid);
        data = bjxxClassWorkInsteadService.queryByPK(data);
        if (data != null && data.getDbid() != null) {

          BjxxClassWorkInsteadBean bean = new BjxxClassWorkInsteadBean();
          bean.setDbid(data.getDbid());
          bean.setEmpid(data.getEmpid());
          bean.setXm(data.getXm());
          bean.setZgh(data.getZgh());
          bean.setApplydate(data.getApplydate() == null ? null
              : DateUtil.formatDate2Str(data.getApplydate(), "yyyy-MM-dd"));
          bean.setStates(data.getStates());
          bean.setDbempid(data.getDbempid());
          bean.setDbxm(data.getDbxm());
          bean.setDbzgh(data.getDbzgh());
          bean.setKsrq(data.getKsrq() == null ? null
              : DateUtil.formatDate2Str(data.getKsrq(), "yyyy-MM-dd"));
          bean.setJsrq(data.getJsrq() == null ? null
              : DateUtil.formatDate2Str(data.getJsrq(), "yyyy-MM-dd"));
          bean.setKsrqfw(data.getKsrqfw());
          bean.setJsrqfw(data.getJsrqfw());
          bean.setDays(String.valueOf(data.getDays()));
          bean.setReasons(data.getReasons());
          bean.setRemark(data.getRemark());
          bean.setAuditorid(data.getAuditorid());
          bean.setAuditorname(data.getAuditorname());
          bean.setAudittime(data.getAudittime() == null ? null
              : DateUtil.formatDate2Str(data.getAudittime(), "yyyy-MM-dd"));
          bean.setAuditresult(data.getAuditresult());

          BjxxClassWorkInsteadAtt att = new BjxxClassWorkInsteadAtt();
          att.setParentid(data.getDbid());
          List<BjxxClassWorkInsteadAtt> attList = bjxxClassWorkInsteadAttService.queryList(att);

          List<EmployeeBean> employeeBeanlist = new ArrayList<EmployeeBean>();
          if (attList != null && !attList.isEmpty()) {
            for (BjxxClassWorkInsteadAtt r : attList) {
              EmployeeBean employeeBean = new EmployeeBean();
              employeeBean.setEmid(r.getEmpid());
              employeeBean.setZgh(r.getZgh());
              employeeBean.setXm(r.getXm());
              employeeBeanlist.add(employeeBean);
            }
          } else {
            java.util.List<Employee> list = commonService.getqueryStudentClassByBzr(new Student());
            for (Employee r : list) {
              EmployeeBean employeeBean = new EmployeeBean();
              employeeBean.setEmid(r.getEmid());
              employeeBean.setZgh(r.getZgh());
              employeeBean.setXm(r.getXm());
              employeeBeanlist.add(employeeBean);
            }
          }
          dataMap.put("data", bean);
          dataMap.put("dataEmployeeList", employeeBeanlist);
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "查询信息失败,网络异常");
          return dataMap;
        }
        dataMap.put("status", "success");
        dataMap.put("msg", "成功");
      }
    } catch (

    Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 
   * 顶班申请新增修改人员接口
   * 
   * @param SyncValdateSecret
   * @param type
   * @param uid
   * @param dbid
   * @return
   */
  @RequestMapping(value = "/employeeList", produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> employeeList(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }
        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        if (userEmployee != null) {
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
          return dataMap;
        }
        java.util.List<Employee> employeelist =
            commonService.getqueryStudentClassByBzr(new Student());
        if (employeelist != null && !employeelist.isEmpty()) {
          List<EmployeeBean> list = new ArrayList<EmployeeBean>();
          for (Employee r : employeelist) {
            EmployeeBean bean = new EmployeeBean();
            bean.setEmid(r.getEmid());
            bean.setZgh(r.getZgh());
            bean.setXm(r.getXm());
            list.add(bean);
          }
          dataMap.put("dataList", list);
          dataMap.put("status", "success");
          dataMap.put("msg", "查询成功");
        } else {
          dataMap.put("dataList", new ArrayList<EmployeeBean>());
          dataMap.put("status", "success");
          dataMap.put("msg", "查询成功");
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

  /**
   * 
   * 顶班审核通过接口
   * 
   * @param SyncValdateSecret
   * @param type
   * @param uid
   * @param dbid
   * @return
   */
  @RequestMapping(value = "/throughBjxxClassWorkInstead",
      produces = "application/json;charset=utf-8")
  public @ResponseBody Map<String, Object> throughBjxxClassWorkInstead(
      @RequestParam(value = "secretKey", required = true) String SyncValdateSecret,
      @RequestParam(value = "type", required = true) String type,
      @RequestParam(value = "uid", required = true) Integer uid,
      @RequestParam(value = "dbid", required = true) Integer dbid,
      @RequestParam(value = "dbempid", required = true) Integer dbempid,
      @RequestParam(value = "auditresult") String auditresult) {
    Map<String, Object> dataMap = new HashMap<String, Object>();
    try {
      boolean bool = SyncValdateJson.SyncValdateSecret(SyncValdateSecret, dataMap);
      if (bool == true) {
        if (uid == null || StringUtils.isNullValue(type)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "参数用户不能为空或用户类型不能为空,请您核查您的用户或类型信息否不为空!");
          return dataMap;
        }
        if (dbid == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "顶班ID不能为空");
          return dataMap;
        }
        if (dbempid == null) {
          dataMap.put("status", "error");
          dataMap.put("msg", "顶班人教职工id不能为空");
          return dataMap;
        }

        if (StringUtils.isNullValue(auditresult)) {
          dataMap.put("status", "error");
          dataMap.put("msg", "审核意见不能为空!");
          return dataMap;
        }

        UserEmployee user = new UserEmployee();
        user.setUid(uid);
        UserEmployee userEmployee = commonService.queryUserByEmployee(user);
        if (userEmployee != null) {
        } else {
          dataMap.put("status", "error");
          dataMap.put("msg", "系统未找到对应的用户信息，或当前用户未绑定教职工id");
          return dataMap;
        }
        BjxxClassWorkInstead data = new BjxxClassWorkInstead();
        data.setDbid(dbid);
        data = bjxxClassWorkInsteadService.queryByPK(data);
        data.setStates(2);
        data.setAuditresult(auditresult);
        data.setAuditorid(userEmployee.getEmid() == null ? null : userEmployee.getEmid());
        data.setAuditorname(userEmployee.getXm());
        data.setAudittime(new Date());

        java.util.List<Employee> list = commonService.getqueryStudentClassByBzr(new Student());
        for (Employee r : list) {
          if (r.getEmid().intValue() == dbempid.intValue()) {
            data.setDbxm(r.getXm());
            data.setDbzgh(r.getZgh());
            data.setDbempid(r.getEmid());
            break;
          }

        }
        bjxxClassWorkInsteadService.update(data);
        dataMap.put("status", "success");
        dataMap.put("msg", "成功");
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改信息调用services网络异常", e);
      dataMap.put("status", "error");
      dataMap.put("msg", "修改信息失败,网络异常");
      return dataMap;
    }
    return dataMap;
  }

}
